﻿//SpeechLogListener.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Logging
{
	using System.Collections.Generic;
	using System.Speech.Synthesis;

	/// <summary>
	/// Логгер, произносящий слова при получении сообщения.
	/// </summary>
	public class SpeechLogListener : LogListener
	{
		/// <summary>
		/// Создать <see cref="SpeechLogListener"/>.
		/// </summary>
		public SpeechLogListener()
		{
		}

		/// <summary>
		/// Уровень громкости.
		/// </summary>
		public int Volume { get; set; }

		/// <summary>
		/// Записать сообщения.
		/// </summary>
		/// <param name="messages">Отладочные сообщения.</param>
		protected override void OnWriteMessages(IEnumerable<LogMessage> messages)
		{
			using (var speech = new SpeechSynthesizer { Volume = Volume })
			{
				foreach (var message in messages)
					speech.Speak(message.Message);
			}
		}
	}
}